<!DOCTYPE >
    <html >
<head>
    <meta charset="UTF-8">
    <title>供应商产品添加</title>
    <!-- 引入 layui.css -->
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <META content="MSHTML 6.00.2900.5626" name=GENERATOR></HEAD>

<!--<style>-->
<!--    *{-->
<!--        background-color: #FFFAE3;-->
<!--    }-->
<!--</style>-->
</head>
    <body>
    <script id="button" type="text/html">
        <a class="layui-btn layui-btn-sm"   lay-event="update">
            修改
        </a>
        <a class="layui-btn layui-btn-sm"   lay-event="delete">
           删除
        </a>
    </script>

    <script>
        layui.use('table', function(){
            var table = layui.table;

            //遍历查询出来的结果
            table.render({
                elem: '#demo'
                ,url: '/MaterialType/product_category_maintenance.html' //数据接口 方法的地址
                ,cellMinWidth: 80
                , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    , groups: 1 //只显示 1 个连续页码
                    , first: false//不显示首页
                    , last: false //不显示尾页
                }
                ,
                cols: [
                    [ //表头的字段
                        {field: 'id', title: 'ID', sort: true, fixed: 'left',},
                        {field: 'materialNumber', title: '类型编号', sort: true},
                        {field: 'nameOfGoods', title: '类型名称', sort: true},
                        {field: 'materialDescription', title: '描述',  sort: true},
                        {title: '操作', toolbar: "#button",align:'center'}

                    ]
                ],id:'tableAll',
            });

            table.on('tool(demo)', function(obj){
                let data = obj.data;
                let id = data["id"];
                if(obj.event === 'update'){ //修改
                    // alert("修改事件的id："+id);
                    location.href="/MaterialType/product_class_update.html?id="+id;
                }
                if(obj.event === 'delete'){ //删除
                    // alert("点击删除事件")
                    $.ajax({
                        url: "/MaterialType/DeleteMaterialType.html",
                        data:{
                            "id":id,
                        },
                        type: "POST",
                        success: function (result) {
                            if(result>0){
                                // layer.msg('温馨提示，删除成功')
                                setTimeout('window.location.reload()',1000);
                            }
                            else{
                                layer.msg('温馨提示，删除失败')
                                this.location.reload();
                            }
                        },
                        async: false
                    })
                    layer.close(index);
                }
            });
            //搜索事件 嗨嗨嗨！
            $('#search').on('click', function(){
                // alert("你点击了搜索按钮");
                // alert($('#MATERIAL_NUM').val());
                table.reload('tableAll', {
                    method : 'get',
                    /*url:'/contractmanager/byName',//这个不写表示使用table中的请求*/
                    where : {
                        materialNumber : $.trim($('#materialNumber').val()),
                        nameOfGoods : $.trim($('#nameOfGoods').val())
                    },
                    page : {
                        curr : 1
                    }
                });
                return false;
            });
        });
    </script>
    <table class="layui-table" cellSpacing=1 cellPadding=3 width="100%" border=1 style="background-color: #FFFAE3">
        <form >
        <tr bgColor=#FFFAE3>
            <td align=middle width="100%" bgColor=#ffffff colSpan=20 height=22 style="background-color: #FFFAE3">
                <H2>
                    <b color=#0070c0>产品类别维护页面</b>
                </H2>
            </td>
        </tr>
        <tr bgColor=#FFFAE3>
            <td colspan="9"  align=middle >
                <form name=form action="" method=post>
                    类型编号：<div class="layui-input-inline">
                    <input type="text" id="materialNumber" name="materialNumber" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" style="background-color: #FFFAE3">
                </div>
                    类型名称：  <div class="layui-input-inline">
                    <input type="text"id="nameOfGoods" name="nameOfGoods" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" style="background-color: #FFFAE3">
                </div>
                    <button type="button" class="layui-btn" style="margin-left: 25px;width: 80px;" id="search">查询</button>
                </form>
            </td>
        </tr>
        </form>
        <tr bgColor=#FFFAE3>
            <td colspan="11">
                <button type="button" class="layui-btn layui-btn-sm"  onclick="javascript:window.location.href='/supplier/product_class_add.html'">
                    <i class="layui-icon">新增</i>
                </button>
            </td>
        </tr>
        <tr>
          <td>
              <table  id="demo" lay-filter="demo" width="100%" style="height: 100%" >
              </table>
          </td>
        </tr>
    </table>
    </body>
    </html>